\documentclass{article}
\usepackage{amsmath}
\begin{document}

%% in-text formula, use \(..\), $..$, \begin{math} .. \end{math}
%% in-text formula

%% if $\alpha = 2$, then $\alpha^3=8$



%% %% display formula, use \[..]\, \begin{displaymath} .. \end{displaymath}
%% display formula

%% \[
%% \lim_{n \to \infty}
%% \sum_{k=1}^n \frac{1}{k^2} = \frac{\pi^2}{6}
%% \]

the PP[4] must be 0 !!!

\begin{equation}
  a \cdot b = \sum_{i=0}^{4} PP[i] \cdot 4^i
\end{equation}

for signed or unsigned mode,
\begin{equation}
  PP[i] = -S_{ppi} \cdot 2^9 + \sum_{k=0}^8 PP[i][k] \cdot 2^k
\end{equation}
the last PP only has 8 bits, it must be positive (multiplicand $\cdot$ (+1)) or 0, so $S_{pp4}=0$ and the 9 bit is the sign bit $S_{pp4}$,
\begin{equation}
  PP[4] = \sum_{k=0}^7 PP[4][k] \cdot 2^k = -S_{pp4} \cdot 2^9 + \sum_{k=0}^8 PP[4][k] \cdot 2^k
\end{equation}
it's fit for the equations ...

here, we suppose only the actual bits of PP[i] is plused, the sign bits(extended) is ignored,
\begin{equation}
  PP[i]^{\prime} = \sum_{k=0}^8 PP[i][k] \cdot 2^k = PP[i]+S_{ppi} \cdot 2^9
\end{equation}

the max value of $PP[i]^{\prime}$ is $2^9-1 (i=0,1,2,3); 2^8-1 (i=4)$ \\
for the last PP, the equation above is also correct. The sum of all bits ignore all extended sign bits is,
\begin{equation}
  \sum_{i=0}^{4} PP[i]^{\prime} \cdot 4^i = \sum_{i=0}^{4} PP[i] \cdot 4^i + \sum_{i=0}^{4} S_{ppi} \cdot 2^9 \cdot 4^i = \underline{a \cdot b + \sum_{i=0}^{4} \overline{E_i} \cdot 2^{9+2i}}
\end{equation}

%% the sum of all sign bits
\begin{equation}
\begin{aligned}
  sum(sign) = \sum_{i=9}^{15} S_{pp0} \cdot 2^i +  \sum_{i=11}^{15} S_{pp1} \cdot 2^i + \sum_{i=13}^{15} S_{pp2} \cdot 2^i + \sum_{i=15}^{15} S_{pp3} \cdot 2^i \\
  = S_{pp0} \cdot (2^{16}-2^9) + S_{pp1} \cdot (2^{16}-2^{11}) + S_{pp2} \cdot (2^{16}-2^{13}) + S_{pp3} \cdot (2^{16}-2^{15})  \\
= (S_{pp0} + S_{pp1} + S_{pp2} + S_{pp3}) \cdot 2^{16} - S_{pp0} \cdot 2^9 - S_{pp1} \cdot 2^{11} - S_{pp2} \cdot 2^{13} - S_{pp3} \cdot 2^{15} \\
= (\overline{S_{pp0}}-1) \cdot 2^9 + (\overline{S_{pp1}}-1) \cdot 2^{11} + (\overline{S_{pp2}}-1) \cdot 2^{13} + (\overline{S_{pp3}}-1) \cdot 2^{15} \\
= (\overline{S_{pp0}} \cdot 2^9 + \overline{S_{pp1}} \cdot 2^{11} + \overline{S_{pp2}} \cdot 2^{13} + \overline{S_{pp3}} \cdot 2^{15}) - (2^9+2^{11}+2^{13}+2^{15}) \\
= (\overline{S_{pp0}} \cdot 2^9 + \overline{S_{pp1}} \cdot 2^{11} + \overline{S_{pp2}} \cdot 2^{13} + \overline{S_{pp3}} \cdot 2^{15}) + 2^{16} - (2^9+2^{11}+2^{13}+2^{15}) \\
= (\overline{S_{pp0}} \cdot 2^9 + \overline{S_{pp1}} \cdot 2^{11} + \overline{S_{pp2}} \cdot 2^{13} + \overline{S_{pp3}} \cdot 2^{15}) + (2^{14} +2^{12}+2^{10}+2^9) \\
= \underline{(E_0 \cdot 2^9 + E_1 \cdot 2^{11} + E_2 \cdot 2^{13} + E_3 \cdot 2^{15}) + (2^{14} +2^{12}+2^{10}+2^9)}
\end{aligned}
\end{equation}

the sum of all bits(after sign compensation, treat every PP as a unsigned number),
\begin{equation}
\begin{aligned}
  sum(all-bits) = \sum_{i=0}^{4} PP[i]^{\prime} \cdot 4^i + sum(sign-compensation) \\
  = \underbrace{ab + (\overline{E_0} \cdot 2^{9} + \overline{E_1} \cdot 2^{11} + \overline{E_2} \cdot 2^{13} + \overline{E_3} \cdot 2^{15})}_{\sum_{i=0}^{4} PP[i]^{\prime} \cdot 4^i} + \underline{(E_0 \cdot 2^9 + E_1 \cdot 2^{11} + E_2 \cdot 2^{13} + E_3 \cdot 2^{15}) + (2^{14} +2^{12}+2^{10}+2^9)} \\
  = ab + 2^{16}
\end{aligned}
\end{equation}
the result should overflow for 1 bit(only one) if the product $ab$ is positive or 0, but not when negative \\

%% \begin{equation}
%%   sum(all-bits) = ab + 2^{15} + (\overline{E_3}+E_3) \cdot 2^{15}
%% \end{equation}

for signed mode, 
\begin{equation}
  sum(all-bits) = ab + (\overline{E_0}+E_0) \cdot 2^{9} + (\overline{E_1}+E_1) \cdot 2^{11} + (\overline{E_2}+E_2) \cdot 2^{13} + (\overline{E_3}+E_3) \cdot 2^{15} + 2^9 + 2^{10} + 2^{12} + 2^{14}
\end{equation}

now, we strip the $2^{14}$ term,
\begin{equation}
  sum(all-bits) = ab + 2^{14} + 2^{15}
\end{equation}

only when $ab = 2^{14} (a=-2^7 \cdot -2^7)$, the sum will overflow and generate 1 carry bit, so we need strip another '1'(any) to ensure the sum will not overflow



 --but, here notice, '111' must treated as 0 (the same with '000'), otherwise ----???
%% when $a<0, b<0$, booth2 code $\underbrace{11|1}_{0} \underbrace{xx}_{<=0}$, so the sign of PP[3] is 0 (positive or 0), $E[3]=1$, $\overline{E[3]}=0$;
%% when $a>=0, b>=0$, booth2 code $\underbrace{00|0}_{0} \underbrace{xx}_{>=0}$, so the sign of PP[3] is 0 (positive or 0), $E[3]=1$, $\overline{E[3]}=0$, strip the $E[3]$ from the sign compensation, then
%% \begin{equation}
%%   sum(all-bits) = ab + 2^{15} < 2^{16}-1
%% \end{equation}
%% so the sum operation will never overflow if $E[3]$(the MSB of sign compensation) is striped.

\begin{equation}
  max(\sum_{i=0}^{4} PP[i]^{\prime} \cdot 4^i) = \sum_{i=0}^{3} (2^9-1) \cdot 2^{2i} + (2^8-1) \cdot 2^8
\end{equation}


\begin{equation}
  c - a \cdot b = -(a \cdot b - c) = -(a \cdot b + \overline{c} + 1) = \overline{a \cdot b + \overline{c}}
\end{equation}

\begin{equation}
  c - a \cdot b + k = -(a \cdot b - c - k) = -(a \cdot b + \overline{c} + 1 - k ) = \overline{a \cdot b + \overline{c} - k } = \overline{a \cdot b + \overline{c} + (\overline{k} + 1)}
\end{equation}


\begin{equation}
\begin{aligned}
  a - b = \sum_{i=0}^{n-1} a_i \cdot 2^i - \sum_{i=0}^{n-1} b_i \cdot 2^i = \sum_{i=0}^{n-1} (a_i-b_i) \cdot 2^i \\
  = \sum_{i=0}^{n-1} (a_i + \overline{b_i} - 1) \cdot 2^i = \sum_{i=0}^{n-1} (a_i + \overline{b_i}) \cdot 2^i - \sum_{i=0}^{n-1} 2^i \\
  = a + \overline{b} - (2^n-1) = a + \overline{b} + 1 - 2^n
\end{aligned}
\end{equation}

if $a-b<0$ (borrow occur), then $a+\overline{b}+1-2^n<0 \rightarrow a+\overline{b}+1<2^n or a+\overline{b}+1<=2^n-1$ (no carry) \\
if $a-b>=0$ (no borrow), then $a+\overline{b}+1-2^n>=0 \rightarrow a+\overline{b}+1>=2^n$ (carry occur) \\
so, \\
$a-b$ (borrow occur) $\rightarrow a+\overline{b}+1$ (no carry) \\
$a-b$ (no borrow) $\rightarrow a+\overline{b}+1$ (carry occur) \\


\begin{equation}
\begin{aligned}
  a - b = -(b-a) = -(\sum_{i=0}^{n-1} b_i \cdot 2^i - \sum_{i=0}^{n-1} a_i \cdot 2^i) = -\sum_{i=0}^{n-1} (b_i-a_i) \cdot 2^i \\
  = -\sum_{i=0}^{n-1} (b_i + \overline{a_i}-1) \cdot 2^i = -\sum_{i=0}^{n-1} (b_i + \overline{a_i}) \cdot 2^i + \sum_{i=0}^{n-1} 2^i \\
 = -c + (2^n-1), c = \overline{a} + b \\
 = \sum_{i=0}^{n-1} (-c_i) \cdot 2^i + (2^n-1) \\
 = \sum_{i=0}^{n-1} (\overline{c_i}-1) \cdot 2^i + (2^n-1) \\
 = \sum_{i=0}^{n-1} \overline{c_i} \cdot 2^i - \sum_{i=0}^{n-1} 2^i + (2^n-1) \\
 = \overline{c_i} = \overline{\overline{a}+b}
\end{aligned}
\end{equation}


(treat all as unsigned number ?)
\begin{equation}
\begin{aligned}
  \overline{a} + b = 2^n - 1 - a + b = (2^n-1) + b-a > 2^n-1 (carry occur) \\
  a<b \rightarrow \overline{a} + b : carry occur \rightarrow a-b : borrow occur
\end{aligned}
\end{equation}

\begin{equation}
\begin{aligned}
  \overline{a} = \sum_{i=0}^{n-1} \overline{a_i} \cdot 2^i = \sum_{i=0}^{n-1} (1-a_i) \cdot 2^i \\
  = \sum_{i=0}^{n-1} \cdot 2^i - \sum_{i=0}^{n-1} a_i \cdot 2^i \\
  = 2^n - 1 - a
\end{aligned}
\end{equation}




\end{document}

